package se.webbzon.oschi01.resourceset;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;

public abstract class ResourceSetLoader<R> {
	
	// A collection of all resources loaded into the resource set
	private final Collection<R> resources;
		
	/*============================================================
	Constructors
	============================================================*/
		
	/** Creates a new generic ResourceSetLoader. **/
	public ResourceSetLoader() {
		resources = new ArrayList<R>();
	}
		
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns a new resource set which contains all resources added 
	 * by the ResourceSetLoader. **/
	public ResourceSet<R> getResourceSet() {
		return new ResourceSet<R>(resources);
	}
	
	/** Adds a resource to the end of the resource set. **/
	public boolean addResource(R resource) {
		return resources.add(resource);
	}
	
	/** Adds a collection of resources to the end of the resource set. **/
	public boolean addResources(Collection<R> resources) {
		return this.resources.addAll(resources);
	}
	
	/** Returns true if the resource set loader can load resources by using
	 * an Uniform Resource Identifier (URI).**/
	public abstract boolean supportsAddFromURL();
	
	/** Adds a resource by loading it from an Uniform Resource Locator (URL). **/
	public abstract boolean addFromURL(URL resourceURL) throws ResourceSetLoaderException;

	/** Returns true if the resource set loader can load resources by using
	 * an input stream. **/
	public abstract boolean supportsAddFromInputStream();
	
	/** Adds a resource from an input stream. **/
	public abstract boolean addFromInputStream(InputStream inputStream) throws ResourceSetLoaderException;
	
}
